package com.lagou.subjectthree;

import java.util.HashMap;

/**
 * 统计HashMap各个数字字符串出现的次数
 */
public class SubjectThreeMain {
    public static void main(String[] args) {
        String total = "123,456,789,123,456";
        System.out.println("字符串：" + total);
        //申明
        HashMap<String, Integer> hashMap = new HashMap<>();
        //分割字符串
        String[] ss = total.split(",");
        for (String s : ss) {
            int count = 0;
            if (hashMap.containsKey(s))
                //如果map有值了，就原来值增加1
                count = hashMap.get(s) + 1;
            else
                count++;
            hashMap.put(s, count);
        }

        //打印map
        for (String s : hashMap.keySet()) {
            System.out.println(s + "出现了" + hashMap.get(s) + "次");
        }

    }

}
